﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace LiAnProxy
{
    public delegate void ReturnHandle(ProxyModel socketModel);
    public partial class AddSocket : Form
    {

        public ReturnHandle ReturnDelegate;

        public AddSocket()
        {
            InitializeComponent();
        }

        private void ConfirmBtn_Click(object sender, EventArgs e)
        {
            ProxyModel socketModel = null;
            try
            {
                int port;
                int targetPort;
                if (!int.TryParse(txtPort.Text, out port))
                {
                    MessageBox.Show(@"代理端口不是合法的数字", @"错误");
                    return;
                }
                if (!int.TryParse(targetPortTxt.Text, out targetPort))
                {
                    MessageBox.Show(@"输入值不是合法的数字", @"错误");
                    return;
                }
                socketModel = new ProxyModel
                {
                    ProxyName= NameText.Text,
                    ProxyType = ProxyType.Socket,
                    ProxyPort = port,
                    ProxyIp = ProxyIpTxt.Text.Trim(),
                    TargetIp = targetIpTxt.Text,
                    TargetPort = targetPort,
                    TargetTimeOut = Convert.ToInt32(TargetTimeOutText.Text),
                    ProxyMax = Convert.ToInt32(ProxyMaxText.Text)
                };
            }
            catch (Exception ex)
            {
                MessageBox.Show(@"错误", ex.Message);
            }
            if (ReturnDelegate != null)
                ReturnDelegate(socketModel);
            Close();
        }


    }
}
